package com.pigs.pigsordersystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pigs.pigsordersystem.service.IUsersService;
import com.pigs.pigsordersystem.entity.UsersEntity;
import com.pigs.pigsordersystem.mapper.UsersMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 客户service 实现类
 *
 * @author Y.yang
 * @since 2020-03-14
 */
@Transactional
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, UsersEntity> implements IUsersService {


    @Autowired
    private UsersMapper usersMapper;

    private AbstractWrapper wrapper = new QueryWrapper<UsersEntity>();

    /**
     * 查询客户信息
     * 分页
     * 实现方法
     *
     * @param page
     * @return
     */
    @Override
    public IPage<UsersEntity> queryUserList(Page page, AbstractWrapper wrapper) {

        return usersMapper.selectPage(page, wrapper);
    }

    /**
     * 客户登录
     *
     * @param name
     * @param userPassword
     * @return
     */
    @Override
    public UsersEntity loginUser(String name, String userPassword) {
        if (!name.isEmpty() && !userPassword.isEmpty()) {
            String adminPassMd5 = DigestUtils.md5Hex(userPassword);
            UsersEntity usersEntity = usersMapper.loginUser(name, adminPassMd5);

            return usersEntity;

        }
        return null;
    }
}
